package com.fcl.oschina.ui.fragment;

import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.fcl.mylibrary.reflect.ViewInject;
import com.fcl.mylibrary.ui.BaseFragment;
import com.fcl.mylibrary.ui.adapter.MainTabAdapter;
import com.fcl.oschina.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Administrator on 2017/3/15.
 */

public class HomeFragment extends BaseFragment {

    private MainTabAdapter mPagerAdapter;
    private List<Fragment> mFragments = new ArrayList<>();
    private List<String> mTitles = Arrays.asList("资讯", "博客", "热门动弹");

    @ViewInject(R.id.tab_layout)
    TabLayout mTabLayout;

    @ViewInject(R.id.pager)
    ViewPager mPager;

    @Override
    protected void init() {
        super.init();
        initFragment();
        mPagerAdapter = new MainTabAdapter(getChildFragmentManager(), getContext(), mFragments, mTitles);
        mPager.setAdapter(mPagerAdapter);
        mTabLayout.setupWithViewPager(mPager);
        mTabLayout.setSelectedTabIndicatorColor(Color.WHITE);
        mTabLayout.setTabTextColors(getResources().getColor(R.color.colorSecondaryText),
                getResources().getColor(R.color.colorText));
    }

    private void initFragment() {
        mFragments.clear();
        mFragments.add(new NewsFragment());
        mFragments.add(new BlogFragment());
        mFragments.add(new TweetFragment());
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_home;
    }
}
